import _ from 'lodash'

const MAX_NUM = 14       //格式化后的最长限制
const DECIMAL_NUM = 7    //四舍五入时小数点后位数
const EXPONENTIAL_NUM = 4 //科学计数法小数点后位数

const CONFIG = {
    "length": {
        "name": "长度",
        "main": "米",
        "unit": [
            {
                "name": "千米",
                "zh": "千米",
                "en": "km",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            },
            {
                "name": "米",
                "zh": "米",
                "en": "m",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "分米",
                "zh": "分米",
                "en": "dm",
                "calc": (x) => (x * 1) / 0.1,
                "init": (x) => (x * 0.1)
            },
            {
                "name": "厘米",
                "zh": "厘米",
                "en": "cm",
                "calc": (x) => (x * 1) / 0.01,
                "init": (x) => (x * 0.01)
            },
            {
                "name": "毫米",
                "zh": "毫米",
                "en": "mm",
                "calc": (x) => (x * 1) / 0.001,
                "init": (x) => (x * 0.001)
            },
            {
                "name": "微米",
                "zh": "微米",
                "en": "um",
                "calc": (x) => (x * 1) / 0.000001,
                "init": (x) => (x * 0.000001)
            },
            {
                "name": "纳米",
                "zh": "纳米",
                "en": "nm",
                "calc": (x) => (x * 1) / 0.000000001,
                "init": (x) => (x * 0.000000001)
            },
            {
                "name": "皮米",
                "zh": "皮米",
                "en": "pm",
                "calc": (x) => (x * 1) / 0.000000000001,
                "init": (x) => (x * 0.000000000001)
            },
            {
                "name": "光年",
                "zh": "光年",
                "en": "ly",
                "calc": (x) => (x * 1) / 9460730472580800,
                "init": (x) => (x * 9460730472580800)
            },
            {
                "name": "天文单位",
                "zh": "天文单位",
                "en": "AU",
                "calc": (x) => (x * 1) / 149597870700,
                "init": (x) => (x * 149600000000)
            },
            {
                "name": "英寸",
                "zh": "英寸",
                "en": "in",
                "calc": (x) => (x * 1) / (0.3048 / 12),
                "init": (x) => (x * (0.3048 / 12))
            },
            {
                "name": "英尺",
                "zh": "英尺",
                "en": "ft",
                "calc": (x) => (x * 1) / 0.3048,
                "init": (x) => (x * 0.3048)
            },
            {
                "name": "码",
                "zh": "码",
                "en": "yd",
                "calc": (x) => (x * 1) / (0.3048 * 3),
                "init": (x) => (x * (0.3048 * 3))
            },
            {
                "name": "英里",
                "zh": "英里",
                "en": "mi",
                "calc": (x) => (x * 1) / (0.3048 * 3 * 1760),
                "init": (x) => (x * (0.3048 * 3 * 1760))
            },
            {
                "name": "海里",
                "zh": "海里",
                "en": "nmi",
                "calc": (x) => (x * 1) / 1852,
                "init": (x) => (x * 1852)
            },
            {
                "name": "英寻",
                "zh": "英寻",
                "en": "fm",
                "calc": (x) => (x * 1) / 1.8288,
                "init": (x) => (x * 1.8288)
            },
            {
                "name": "弗隆",
                "zh": "弗隆",
                "en": "fur",
                "calc": (x) => (x * 1) / 201.168,
                "init": (x) => (x * 201.168)
            },
            {
                "name": "里",
                "zh": "里",
                "en": "",
                "calc": (x) => (x * 1) / 500,
                "init": (x) => (x * 500)
            },
            {
                "name": "丈",
                "zh": "丈",
                "en": "",
                "calc": (x) => (x * 1) / (10 / 3),
                "init": (x) => (x * (10 / 3))
            },
            {
                "name": "尺",
                "zh": "尺",
                "en": "",
                "calc": (x) => (x * 1) / (1 / 3),
                "init": (x) => (x * (1 / 3))
            },
            {
                "name": "寸",
                "zh": "寸",
                "en": "",
                "calc": (x) => (x * 1) / (0.1 / 3),
                "init": (x) => (x * (0.1 / 3))
            },
            {
                "name": "分",
                "zh": "分",
                "en": "",
                "calc": (x) => (x * 1) / (0.01 / 3),
                "init": (x) => (x * (0.01 / 3))
            },
            {
                "name": "厘",
                "zh": "厘",
                "en": "",
                "calc": (x) => (x * 1) / (0.001 / 3),
                "init": (x) => (x * (0.001 / 3))
            },
            {
                "name": "毫",
                "zh": "毫",
                "en": "",
                "calc": (x) => (x * 1) / (0.0001 / 3),
                "init": (x) => (x * (0.0001 / 3))
            }
        ],
        "special": [],
        "group": [
            {
                "name": "公制",
                "list": [
                    "千米",
                    "米",
                    "分米",
                    "厘米",
                    "毫米",
                    "微米",
                    "纳米",
                    "皮米",
                    "光年",
                    "天文单位"
                ]
            },
            {
                "name": "英制",
                "list": [
                    "英寸",
                    "英尺",
                    "码",
                    "英里",
                    "海里",
                    "英寻",
                    "弗隆"
                ]
            },
            {
                "name": "市制",
                "list": [
                    "里",
                    "丈",
                    "尺",
                    "寸",
                    "分",
                    "厘",
                    "毫"
                ]
            }
        ]
    },
    "area": {
        "name": "面积",
        "main": "平方米",
        "unit": [
            {
                "name": "平方千米",
                "zh": "平方千米",
                "en": "km²",
                "calc": (x) => (x * 1) / 1000000,
                "init": (x) => (x * 1000000)
            },
            {
                "name": "公顷",
                "zh": "公顷",
                "en": "ha",
                "calc": (x) => (x * 1) / 10000,
                "init": (x) => (x * 10000)
            },
            {
                "name": "公亩",
                "zh": "公亩",
                "en": "are",
                "calc": (x) => (x * 1) / 100,
                "init": (x) => (x * 100)
            },
            {
                "name": "平方米",
                "zh": "平方米",
                "en": "㎡",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "平方分米",
                "zh": "平方分米",
                "en": "dm²",
                "calc": (x) => (x * 1) / 0.01,
                "init": (x) => (x * 0.01)
            },
            {
                "name": "平方厘米",
                "zh": "平方厘米",
                "en": "cm²",
                "calc": (x) => (x * 1) / 0.0001,
                "init": (x) => (x * 0.0001)
            },
            {
                "name": "平方毫米",
                "zh": "平方毫米",
                "en": "mm²",
                "calc": (x) => (x * 1) / 0.000001,
                "init": (x) => (x * 0.000001)
            },
            {
                "name": "英亩",
                "zh": "英亩",
                "en": "acre",
                "calc": (x) => (x * 1) / (Math.pow(0.3048, 2) * Math.pow(16.5, 2) * 160),
                "init": (x) => (x * (Math.pow(0.3048, 2) * Math.pow(16.5, 2) * 160))
            },
            {
                "name": "平方英里",
                "zh": "平方英里",
                "en": "sq.mi",
                "calc": (x) => (x * 1) / Math.pow((0.3048 * 3 * 1760), 2),
                "init": (x) => (x * Math.pow((0.3048 * 3 * 1760), 2))
            },
            {
                "name": "平方码",
                "zh": "平方码",
                "en": "sq.yd",
                "calc": (x) => (x * 1) / (Math.pow(0.3048, 2) * 9),
                "init": (x) => (x * (Math.pow(0.3048, 2) * 9))
            },
            {
                "name": "平方英尺",
                "zh": "平方英尺",
                "en": "sq.ft",
                "calc": (x) => (x * 1) / Math.pow(0.3048, 2),
                "init": (x) => (x * (Math.pow(0.3048, 2)))
            },
            {
                "name": "平方英寸",
                "zh": "平方英寸",
                "en": "sq.in",
                "calc": (x) => (x * 1) / (Math.pow(0.3048, 2) / 144),
                "init": (x) => (x * (Math.pow(0.3048, 2) / 144))
            },
            {
                "name": "平方竿",
                "zh": "平方竿",
                "en": "sq.rd",
                "calc": (x) => (x * 1) / (Math.pow(0.3048, 2) * Math.pow(16.5, 2)),
                "init": (x) => (x * (Math.pow(0.3048, 2) * Math.pow(16.5, 2)))
            },
            {
                "name": "顷",
                "zh": "顷",
                "en": "",
                "calc": (x) => (x * 1) / (100 / 0.0015),
                "init": (x) => (x * (100 / 0.0015))
            },
            {
                "name": "亩",
                "zh": "亩",
                "en": "",
                "calc": (x) => (x * 1) / (1 / 0.0015),
                "init": (x) => (x * (1 / 0.0015))
            },
            {
                "name": "分",
                "zh": "分",
                "en": "",
                "calc": (x) => (x * 1) / (1 / 0.015),
                "init": (x) => (x * (1 / 0.015))
            },
            {
                "name": "平方尺",
                "zh": "平方尺",
                "en": "",
                "calc": (x) => (x * 1) / (1 / 9),
                "init": (x) => (x * (1 / 9))
            },
            {
                "name": "平方寸",
                "zh": "平方寸",
                "en": "",
                "calc": (x) => (x * 1) / (0.01 / 9),
                "init": (x) => (x * (0.01 / 9))
            }
        ],
        "special": [],
        "group": [
            {
                "name": "公制",
                "list": [
                    "平方千米",
                    "公顷",
                    "公亩",
                    "平方米",
                    "平方分米",
                    "平方厘米",
                    "平方毫米"
                ]
            },
            {
                "name": "英制",
                "list": [
                    "英亩",
                    "平方英里",
                    "平方码",
                    "平方英尺",
                    "平方英寸",
                    "平方竿"
                ]
            },
            {
                "name": "市制",
                "list": [
                    "顷",
                    "亩",
                    "分",
                    "平方尺",
                    "平方寸"
                ]
            }
        ]
    },
    "volume": {
        "name": "体积",
        "main": "立方米",
        "unit": [
            {
                "name": "立方米",
                "zh": "立方米",
                "en": "m³",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "立方分米",
                "zh": "立方分米",
                "en": "dm³",
                "calc": (x) => (x * 1) / 0.001,
                "init": (x) => (x * 0.001)
            },
            {
                "name": "立方厘米",
                "zh": "立方厘米",
                "en": "cm³",
                "calc": (x) => (x * 1) / 0.000001,
                "init": (x) => (x * 0.000001)
            },
            {
                "name": "立方毫米",
                "zh": "立方毫米",
                "en": "mm³",
                "calc": (x) => (x * 1) / 0.000000001,
                "init": (x) => (x * 0.000000001)
            },
            {
                "name": "升",
                "zh": "升",
                "en": "l",
                "calc": (x) => (x * 1) / 0.001,
                "init": (x) => (x * 0.001)
            },
            {
                "name": "分升",
                "zh": "分升",
                "en": "dl",
                "calc": (x) => (x * 1) / 0.0001,
                "init": (x) => (x * 0.0001)
            },
            {
                "name": "毫升",
                "zh": "毫升",
                "en": "ml",
                "calc": (x) => (x * 1) / 0.000001,
                "init": (x) => (x * 0.000001)
            },
            {
                "name": "厘升",
                "zh": "厘升",
                "en": "cl",
                "calc": (x) => (x * 1) / 0.00001,
                "init": (x) => (x * 0.00001)
            },
            {
                "name": "公石",
                "zh": "公石",
                "en": "hl",
                "calc": (x) => (x * 1) / 0.1,
                "init": (x) => (x * 0.1)
            },
            {
                "name": "立方英尺",
                "zh": "立方英尺",
                "en": "cu ft",
                "calc": (x) => (x * 1) / 0.0283168,
                "init": (x) => (x * 0.0283168)
            },
            {
                "name": "立方英寸",
                "zh": "立方英寸",
                "en": "cu in",
                "calc": (x) => (x * 1) / (0.0283168 / 1728),
                "init": (x) => (x * (0.0283168 / 1728))
            },
            {
                "name": "立方码",
                "zh": "立方码",
                "en": "cu yd",
                "calc": (x) => (x * 1) / (0.0283168 * 27),
                "init": (x) => (x * (0.0283168 * 27))
            },
            {
                "name": "亩英尺",
                "zh": "亩英尺",
                "en": "",
                "calc": (x) => (x * 1) / (43560 * 1728 * 0.016387064 / 1000),
                "init": (x) => (x * (43560 * 1728 * 0.016387064 / 1000))
            },
            {
                "name": "英制加仑",
                "zh": "英制加仑",
                "en": "uk gal",
                "calc": (x) => (x * 1) / 0.00454609188,
                "init": (x) => (x * 0.00454609188)
            },
            {
                "name": "美制加仑",
                "zh": "美制加仑",
                "en": "us gal",
                "calc": (x) => (x * 1) / (231 * 0.016387064 / 1000),
                "init": (x) => (x * (231 * 0.016387064 / 1000))
            },
            {
                "name": "微升",
                "zh": "微升",
                "en": "ul",
                "calc": (x) => (x * 1) / 0.000000001,
                "init": (x) => (x * 0.000000001)
            },
            {
                "name": "英制液体盎司",
                "zh": "英制液体盎司",
                "en": "oz",
                "calc": (x) => (x * 1) / (0.000001 * 28.41),
                "init": (x) => (x * 0.000001 * 28.41)
            },
            {
                "name": "美制液体盎司",
                "zh": "美制液体盎司",
                "en": "oz",
                "calc": (x) => (x * 1) / (0.000001 * 29.57),
                "init": (x) => (x * 0.000001 * 29.57)
            }
        ],
        "special": [],
        "group": [
            {
                "name": "公制",
                "list": [
                    "立方米",
                    "立方分米",
                    "立方厘米",
                    "立方毫米",
                    "升",
                    "分升",
                    "毫升",
                    "厘升",
                    "公石",
                    "微升"
                ]
            },
            {
                "name": "英制",
                "list": [
                    "立方英尺",
                    "立方英寸",
                    "立方码",
                    "亩英尺",
                    "英制加仑",
                    "美制加仑",
                    "英制液体盎司",
                    "美制液体盎司"
                ]
            }
        ]
    },
    "weight": {
        "name": "质量",
        "main": "千克",
        "unit": [
            {
                "name": "千克",
                "zh": "千克",
                "en": "kg",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "克",
                "zh": "克",
                "en": "g",
                "calc": (x) => (x * 1) / 0.001,
                "init": (x) => (x * 0.001)
            },
            {
                "name": "毫克",
                "zh": "毫克",
                "en": "mg",
                "calc": (x) => (x * 1) / 0.000001,
                "init": (x) => (x * 0.000001)
            },
            {
                "name": "微克",
                "zh": "微克",
                "en": "μg",
                "calc": (x) => (x * 1) / 0.000000001,
                "init": (x) => (x * 0.000000001)
            },
            {
                "name": "吨",
                "zh": "吨",
                "en": "t",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            },
            {
                "name": "公担",
                "zh": "公担",
                "en": "q",
                "calc": (x) => (x * 1) / 100,
                "init": (x) => (x * 100)
            },
            {
                "name": "磅",
                "zh": "磅",
                "en": "lb",
                "calc": (x) => (x * 1) / 0.45359237,
                "init": (x) => (x * 0.45359237)
            },
            {
                "name": "盎司",
                "zh": "盎司",
                "en": "oz",
                "calc": (x) => (x * 1) / (0.45359237 / 16),
                "init": (x) => (x * (0.45359237 / 16))
            },
            {
                "name": "克拉",
                "zh": "克拉",
                "en": "ct",
                "calc": (x) => (x * 1) / 0.0002,
                "init": (x) => (x * 0.0002)
            },
            {
                "name": "格令",
                "zh": "格令",
                "en": "gr",
                "calc": (x) => (x * 1) / (0.45359237 / 7000),
                "init": (x) => (x * (0.45359237 / 7000))
            },
            {
                "name": "长吨",
                "zh": "长吨",
                "en": "lt",
                "calc": (x) => (x * 1) / (0.45359237 * 2240),
                "init": (x) => (x * (0.45359237 * 2240))
            },
            {
                "name": "短吨",
                "zh": "短吨",
                "en": "st",
                "calc": (x) => (x * 1) / (0.45359237 * 2000),
                "init": (x) => (x * (0.45359237 * 2000))
            },
            {
                "name": "英担",
                "zh": "英担",
                "en": "",
                "calc": (x) => (x * 1) / (0.45359237 * 112),
                "init": (x) => (x * (0.45359237 * 112))
            },
            {
                "name": "美担",
                "zh": "美担",
                "en": "",
                "calc": (x) => (x * 1) / (0.45359237 * 100),
                "init": (x) => (x * (0.45359237 * 100))
            },
            {
                "name": "英石",
                "zh": "英石",
                "en": "st",
                "calc": (x) => (x * 1) / (0.45359237 * 14),
                "init": (x) => (x * (0.45359237 * 14))
            },
            {
                "name": "打兰",
                "zh": "打兰",
                "en": "dr",
                "calc": (x) => (x * 1) / (0.45359237 / 256),
                "init": (x) => (x * (0.45359237 / 256))
            },
            {
                "name": "担",
                "zh": "担",
                "en": "",
                "calc": (x) => (x * 1) / 50,
                "init": (x) => (x * 50)
            },
            {
                "name": "斤",
                "zh": "斤",
                "en": "",
                "calc": (x) => (x * 1) / 0.5,
                "init": (x) => (x * 0.5)
            },
            {
                "name": "两",
                "zh": "两",
                "en": "",
                "calc": (x) => (x * 1) / 0.05,
                "init": (x) => (x * 0.05)
            },
            {
                "name": "钱",
                "zh": "钱",
                "en": "",
                "calc": (x) => (x * 1) / 0.005,
                "init": (x) => (x * 0.005)
            },
            {
                "name": "分",
                "zh": "分",
                "en": "point",
                "calc": (x) => (x * 1) / 0.000002,
                "init": (x) => (x * 0.000002)
            }
        ],
        "special": [],
        "group": [
            {
                "name": "公制",
                "list": [
                    "千克",
                    "克",
                    "毫克",
                    "微克",
                    "吨",
                    "公担",
                    "克拉",
                    "分"
                ]
            },
            {
                "name": "英制",
                "list": [
                    "磅",
                    "盎司",
                    "克拉",
                    "格令",
                    "长吨",
                    "短吨",
                    "英担",
                    "美担",
                    "英石",
                    "打兰"
                ]
            },
            {
                "name": "市制",
                "list": [
                    "担",
                    "斤",
                    "两",
                    "钱"
                ]
            }
        ]
    },
    "temperature": {
        "name": "温度",
        "main": "开氏度",
        "unit": [
            {
                "name": "摄氏度",
                "zh": "摄氏度",
                "en": "℃",
                "calc": (x) => (x - 273.15),
                "init": (x) => (x * 1) + 273.15
            },
            {
                "name": "华氏度",
                "zh": "华氏度",
                "en": "℉",
                "calc": (x) => 32 + ((x - 273.15) * 9 / 5),
                "init": (x) => (5 * (x - 32) / 9) + 273.15
            },
            {
                "name": "开氏度",
                "zh": "开氏度",
                "en": "K",
                "calc": (x) => (x - 273.15) + 273.15,
                "init": (x) => (x - 273.15) + 273.15
            },
            {
                "name": "兰氏度",
                "zh": "兰氏度",
                "en": "°R",
                "calc": (x) => ((x - 273.15) + 273.15) * 1.8,
                "init": (x) => (x / 1.8 - 273.15) + 273.15
            },
            {
                "name": "列氏度",
                "zh": "列氏度",
                "en": "°Re",
                "calc": (x) => (x - 273.15) / 1.25,
                "init": (x) => (x * 1.25) + 273.15
            }
        ],
        "special": [],
        "group": [
            {
                "name": "",
                "list": [
                    "摄氏度",
                    "华氏度",
                    "开氏度",
                    "兰氏度",
                    "列氏度"
                ]
            }
        ]
    },
    "pressure": {
        "name": "压力",
        "main": "帕斯卡",
        "unit": [
            {
                "name": "帕斯卡",
                "zh": "帕斯卡",
                "en": "Pa",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "千帕",
                "zh": "千帕",
                "en": "kpa",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            },
            {
                "name": "百帕",
                "zh": "百帕",
                "en": "hpa",
                "calc": (x) => (x * 1) / 100,
                "init": (x) => (x * 100)
            },
            {
                "name": "标准大气压",
                "zh": "标准大气压",
                "en": "atm",
                "calc": (x) => (x * 1) / 101325,
                "init": (x) => (x * 101325)
            },
            {
                "name": "毫米汞柱",
                "zh": "毫米汞柱",
                "en": "mmHg",
                "calc": (x) => (x * 1) / (101325 / 760),
                "init": (x) => (x * (101325 / 760))
            },
            {
                "name": "英寸汞柱",
                "zh": "英寸汞柱",
                "en": "in Hg",
                "calc": (x) => (x * 1) / (101325 / 760 * 25.4),
                "init": (x) => (x * (101325 / 760 * 25.4))
            },
            {
                "name": "巴",
                "zh": "巴",
                "en": "bar",
                "calc": (x) => (x * 1) / 100000,
                "init": (x) => (x * 100000)
            },
            {
                "name": "毫巴",
                "zh": "毫巴",
                "en": "mbar",
                "calc": (x) => (x * 1) / 100,
                "init": (x) => (x * 100)
            },
            {
                "name": "磅力/平方英尺",
                "zh": "磅力/平方英尺",
                "en": "psf",
                "calc": (x) => (x * 1) / (6894.757 / 144),
                "init": (x) => (x * (6894.757 / 144))
            },
            {
                "name": "磅力/平方英寸",
                "zh": "磅力/平方英寸",
                "en": "psi",
                "calc": (x) => (x * 1) / 6894.757,
                "init": (x) => (x * 6894.757)
            },
            {
                "name": "毫米水柱",
                "zh": "毫米水柱",
                "en": "",
                "calc": (x) => (x * 1) / (1 / 0.101972),
                "init": (x) => (x * (1 / 0.101972))
            },
            {
                "name": "公斤力/平方厘米",
                "zh": "公斤力/平方厘米",
                "en": "kgf/cm²",
                "calc": (x) => (x * 1) / 98066.5,
                "init": (x) => (x * 98066.5)
            },
            {
                "name": "公斤力/平方米",
                "zh": "公斤力/平方米",
                "en": "kgf/㎡",
                "calc": (x) => (x * 1) / 9.80665,
                "init": (x) => (x * 9.80665)
            },
            {
                "name": "兆帕",
                "zh": "兆帕",
                "en": "MPa",
                "calc": (x) => (x * 1) / 1000000,
                "init": (x) => (x * 1000000)
            }
        ],
        "special": [],
        "group": [
            {
                "name": "",
                "list": [
                    "帕斯卡",
                    "兆帕",
                    "千帕",
                    "百帕",
                    "标准大气压",
                    "毫米汞柱",
                    "英寸汞柱",
                    "巴",
                    "毫巴",
                    "磅力/平方英尺",
                    "磅力/平方英寸",
                    "毫米水柱",
                    "公斤力/平方厘米",
                    "公斤力/平方米"
                ]
            }
        ]
    },
    "power": {
        "name": "功率",
        "main": "瓦",
        "unit": [
            {
                "name": "瓦",
                "zh": "瓦",
                "en": "W",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "千瓦",
                "zh": "千瓦",
                "en": "kW",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            },
            {
                "name": "英制马力",
                "zh": "英制马力",
                "en": "hp",
                "calc": (x) => (x * 1) / 745.699872,
                "init": (x) => (x * 745.699872)
            },
            {
                "name": "米制马力",
                "zh": "米制马力",
                "en": "ps",
                "calc": (x) => (x * 1) / (9.80665 * 75),
                "init": (x) => (x * (9.80665 * 75))
            },
            {
                "name": "公斤·米/秒",
                "zh": "公斤·米/秒",
                "en": "kg·m/s",
                "calc": (x) => (x * 1) / 9.80665,
                "init": (x) => (x * 9.80665)
            },
            {
                "name": "千卡/秒",
                "zh": "千卡/秒",
                "en": "kcal/s",
                "calc": (x) => (x * 1) / 4184.1004,
                "init": (x) => (x * 4184.1004)
            },
            {
                "name": "英热单位/秒",
                "zh": "英热单位/秒",
                "en": "Btu/s",
                "calc": (x) => (x * 1) / 1055.05585,
                "init": (x) => (x * 1055.05585)
            },
            {
                "name": "英尺·磅/秒",
                "zh": "英尺·磅/秒",
                "en": "ft·lb/s",
                "calc": (x) => (x * 1) / (745.699872 / 550),
                "init": (x) => (x * (745.699872 / 550))
            },
            {
                "name": "焦耳/秒",
                "zh": "焦耳/秒",
                "en": "J/s",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "牛顿·米/秒",
                "zh": "牛顿·米/秒",
                "en": "N·m/s",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            }
        ],
        "special": [],
        "group": [
            {
                "name": "",
                "list": [
                    "瓦",
                    "千瓦",
                    "英制马力",
                    "米制马力",
                    "公斤·米/秒",
                    "千卡/秒",
                    "英热单位/秒",
                    "英尺·磅/秒",
                    "焦耳/秒",
                    "牛顿·米/秒"
                ]
            }
        ]
    },
    "work": {
        "name": "功/能/热",
        "main": "焦耳",
        "unit": [
            {
                "name": "焦耳",
                "zh": "焦耳",
                "en": "J",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "公斤·米",
                "zh": "公斤·米",
                "en": "kg·m",
                "calc": (x) => (x * 1) / 9.80392157,
                "init": (x) => (x * 9.80392157)
            },
            {
                "name": "米制马力·时",
                "zh": "米制马力·时",
                "en": "ps·h",
                "calc": (x) => (x * 1) / (9.80665 * 75 * 3600),
                "init": (x) => (x * (9.80665 * 75 * 3600))
            },
            {
                "name": "英制马力·时",
                "zh": "英制马力·时",
                "en": "hp·h",
                "calc": (x) => (x * 1) / (745.699872 * 3600),
                "init": (x) => (x * (745.699872 * 3600))
            },
            {
                "name": "千瓦·时",
                "zh": "千瓦·时",
                "en": "kW·h",
                "calc": (x) => (x * 1) / 3600000,
                "init": (x) => (x * 3600000)
            },
            {
                "name": "度",
                "zh": "度",
                "en": "kW·h",
                "calc": (x) => (x * 1) / 3600000,
                "init": (x) => (x * 3600000)
            },
            {
                "name": "卡",
                "zh": "卡",
                "en": "cal",
                "calc": (x) => (x * 1) / 4.185851820846,
                "init": (x) => (x * 4.185851820846)
            },
            {
                "name": "千卡",
                "zh": "千卡",
                "en": "kcal",
                "calc": (x) => (x * 1) / 4185.851820846,
                "init": (x) => (x * 4185.851820846)
            },
            {
                "name": "英热单位",
                "zh": "英热单位",
                "en": "btu",
                "calc": (x) => (x * 1) / 1055.05585262,
                "init": (x) => (x * 1055.05585262)
            },
            {
                "name": "英尺·磅",
                "zh": "英尺·磅",
                "en": "ft·lb",
                "calc": (x) => (x * 1) / 1.3557483731,
                "init": (x) => (x * 1.3557483731)
            },
            {
                "name": "千焦",
                "zh": "千焦",
                "en": "kJ",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            }
        ],
        "special": [],
        "group": [
            {
                "name": "焦耳(J)",
                "list": [
                    "焦耳",
                    "公斤·米",
                    "米制马力·时",
                    "英制马力·时",
                    "千瓦·时",
                    "度",
                    "卡",
                    "千卡",
                    "英热单位",
                    "英尺·磅",
                    "千焦"
                ]
            }
        ]
    },
    "density": {
        "name": "密度",
        "main": "千克/立方米",
        "unit": [
            {
                "name": "千克/立方厘米",
                "zh": "千克/立方厘米",
                "en": "kg/cm³",
                "calc": (x) => (x * 1) / (Math.pow(10, 6)),
                "init": (x) => (x * 1000000)
            },
            {
                "name": "千克/立方分米",
                "zh": "千克/立方分米",
                "en": "kg/dm³",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            },
            {
                "name": "千克/立方米",
                "zh": "千克/立方米",
                "en": "kg/m³",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "克/立方厘米",
                "zh": "克/立方厘米",
                "en": "g/cm³",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            },
            {
                "name": "克/立方分米",
                "zh": "克/立方分米",
                "en": "g/dm³",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "克/立方米",
                "zh": "克/立方米",
                "en": "g/m³",
                "calc": (x) => (x * 1000),
                "init": (x) => (x * 1) / 1000
            }
        ],
        "special": [],
        "group": [
            {
                "name": "",
                "list": [
                    "千克/立方厘米",
                    "千克/立方分米",
                    "千克/立方米",
                    "克/立方厘米",
                    "克/立方分米",
                    "克/立方米"
                ]
            }
        ]
    },
    "strength": {
        "name": "力",
        "main": "牛",
        "unit": [
            {
                "name": "牛",
                "zh": "牛",
                "en": "N",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "千牛",
                "zh": "千牛",
                "en": "kN",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            },
            {
                "name": "千克力",
                "zh": "千克力",
                "en": "kgf",
                "calc": (x) => (x * 101.971621) / 1000,
                "init": (x) => (x * 9.806650)
            },
            {
                "name": "克力",
                "zh": "克力",
                "en": "gf",
                "calc": (x) => (x * 101.971621),
                "init": (x) => (x * 9.806650) / 1000
            },
            {
                "name": "公吨力",
                "zh": "公吨力",
                "en": "tf",
                "calc": (x) => (x * 101.971621) / (Math.pow(10, 6)),
                "init": (x) => (x * 9806.650000)
            },
            {
                "name": "磅力",
                "zh": "磅力",
                "en": "lbf",
                "calc": (x) => (x * 224.808943) / 1000,
                "init": (x) => (x * 4.448222)
            },
            {
                "name": "千磅力",
                "zh": "千磅力",
                "en": "kip",
                "calc": (x) => (x * 224.808943) / (Math.pow(10, 6)),
                "init": (x) => (x * 4448.221615)
            },
            {
                "name": "达因",
                "zh": "达因",
                "en": "dyn",
                "calc": (x) => (x * 100000),
                "init": (x) => (x * 1) / 100000
            }
        ],
        "special": [],
        "group": [
            {
                "name": "",
                "list": [
                    "牛",
                    "千牛",
                    "千克力",
                    "克力",
                    "公吨力",
                    "磅力",
                    "千磅力",
                    "达因"
                ]
            }
        ]
    },
    "time": {
        "name": "时间",
        "main": "秒",
        "unit": [
            {
                "name": "年",
                "zh": "年",
                "en": "yr",
                "calc": (x) => (x * 31.709792) / (Math.pow(10, 9)),
                "init": (x) => (x * 31536000)
            },
            {
                "name": "周",
                "zh": "周",
                "en": "week",
                "calc": (x) => (x * 1.653439) / (Math.pow(10, 6)),
                "init": (x) => (x * 604800)
            },
            {
                "name": "天",
                "zh": "天",
                "en": "d",
                "calc": (x) => (x * 11.574074) / (Math.pow(10, 6)),
                "init": (x) => (x * 86400)
            },
            {
                "name": "时",
                "zh": "时",
                "en": "h",
                "calc": (x) => (x * 277.777778) / (Math.pow(10, 6)),
                "init": (x) => (x * 3600)
            },
            {
                "name": "分",
                "zh": "分",
                "en": "min",
                "calc": (x) => (x * 16.6666667) / 1000,
                "init": (x) => (x * 60)
            },
            {
                "name": "秒",
                "zh": "秒",
                "en": "s",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "毫秒",
                "zh": "毫秒",
                "en": "ms",
                "calc": (x) => (x * 1000),
                "init": (x) => (x * 1) / 1000
            },
            {
                "name": "微秒",
                "zh": "微秒",
                "en": "μs",
                "calc": (x) => (x * 1000000),
                "init": (x) => (x * 1) / 1000000
            },
            {
                "name": "纳秒",
                "zh": "纳秒",
                "en": "ns",
                "calc": (x) => (x * 1000000000),
                "init": (x) => (x * 1) / 1000000000
            }
        ],
        "special": [
            {
                "from": "时",
                "to": "分",
                "func": (x) => (x * 60)
            }
        ],
        "group": [
            {
                "name": "",
                "list": [
                    "年",
                    "周",
                    "天",
                    "时",
                    "分",
                    "秒",
                    "毫秒",
                    "微秒",
                    "纳秒"
                ]
            }
        ]
    },
    "speed": {
        "name": "速度",
        "main": "米/秒",
        "unit": [
            {
                "name": "米/秒",
                "zh": "米/秒",
                "en": "m/s",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "千米/秒",
                "zh": "千米/秒",
                "en": "km/s",
                "calc": (x) => (x * 1) / 1000,
                "init": (x) => (x * 1000)
            },
            {
                "name": "千米/时",
                "zh": "千米/时",
                "en": "km/h",
                "calc": (x) => (x * 3.600000),
                "init": (x) => (x * 277.777778) / 1000
            },
            {
                "name": "光速",
                "zh": "光速",
                "en": "c",
                "calc": (x) => (x * 3.335641) / (Math.pow(10, 9)),
                "init": (x) => (x * 299792458)
            },
            {
                "name": "马赫",
                "zh": "马赫",
                "en": "mach",
                "calc": (x) => (x * 2.938584) / 1000,
                "init": (x) => (x * 340.300000)
            },
            {
                "name": "英里/时",
                "zh": "英里/时",
                "en": "mile/h",
                "calc": (x) => (x * 2.236936),
                "init": (x) => (x * 447.040000) / 1000
            },
            {
                "name": "英寸/秒",
                "zh": "英寸/秒",
                "en": "in/s",
                "calc": (x) => (x * 39.370079),
                "init": (x) => (x * 25.400000) / 1000
            }
        ],
        "special": [],
        "group": [
            {
                "name": "",
                "list": [
                    "米/秒",
                    "千米/秒",
                    "千米/时",
                    "光速",
                    "马赫",
                    "英里/时",
                    "英寸/秒"
                ]
            }
        ]
    },
    "byte": {
        "name": "数据存储",
        "main": "字节",
        "unit": [
            {
                "name": "比特",
                "zh": "比特",
                "en": "bit",
                "calc": (x) => (x * 8),
                "init": (x) => (x * 1) / 8
            },
            {
                "name": "字节",
                "zh": "字节",
                "en": "b",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "千字节",
                "zh": "千字节",
                "en": "kb",
                "calc": (x) => (x * 1) / (Math.pow(2, 10)),
                "init": (x) => (x * 1024)
            },
            {
                "name": "兆字节",
                "zh": "兆字节",
                "en": "mb",
                "calc": (x) => (x * 1) / (Math.pow(2, 20)),
                "init": (x) => (x * Math.pow(2, 20))
            },
            {
                "name": "千兆字节",
                "zh": "千兆字节",
                "en": "gb",
                "calc": (x) => (x * 1) / (Math.pow(2, 30)),
                "init": (x) => (x * Math.pow(2, 30))
            },
            {
                "name": "太字节",
                "zh": "太字节",
                "en": "tb",
                "calc": (x) => (x * 1) / (Math.pow(2, 40)),
                "init": (x) => (x * Math.pow(2, 40))
            },
            {
                "name": "拍字节",
                "zh": "拍字节",
                "en": "pb",
                "calc": (x) => (x * 1) / (Math.pow(2, 50)),
                "init": (x) => (x * Math.pow(2, 50))
            },
            {
                "name": "艾字节",
                "zh": "艾字节",
                "en": "eb",
                "calc": (x) => (x * 1) / (Math.pow(2, 60)),
                "init": (x) => (x * Math.pow(2, 60))
            }
        ],
        "special": [],
        "group": [
            {
                "name": "",
                "list": [
                    "比特",
                    "字节",
                    "千字节",
                    "兆字节",
                    "千兆字节",
                    "太字节",
                    "拍字节",
                    "艾字节"
                ]
            }
        ]
    },
    "angle": {
        "name": "角度",
        "main": "度",
        "unit": [
            {
                "name": "圆周",
                "zh": "圆周",
                "en": "",
                "calc": (x) => (x * 2.777778) / 1000,
                "init": (x) => (x * 360)
            },
            {
                "name": "直角",
                "zh": "直角",
                "en": "",
                "calc": (x) => (x * 11.111111) / 1000,
                "init": (x) => (x * 90)
            },
            {
                "name": "百分度",
                "zh": "百分度",
                "en": "gon",
                "calc": (x) => (x * 1.111111),
                "init": (x) => (x * 900) / 1000
            },
            {
                "name": "度",
                "zh": "度",
                "en": "°",
                "calc": (x) => (x * 1),
                "init": (x) => (x * 1)
            },
            {
                "name": "分",
                "zh": "分",
                "en": " ′",
                "calc": (x) => (x * 60),
                "init": (x) => (x * 16.6666667) / 1000
            },
            {
                "name": "秒",
                "zh": "秒",
                "en": "'",
                "calc": (x) => (x * 3600),
                "init": (x) => (x * 0.2777778) / 1000
            },
            {
                "name": "弧度",
                "zh": "弧度",
                "en": "rad",
                "calc": (x) => (x * 17.453293) / 1000,
                "init": (x) => (x * 57.295780)
            },
            {
                "name": "毫弧度",
                "zh": "毫弧度",
                "en": "mrad",
                "calc": (x) => (x * 17.453293),
                "init": (x) => (x * 57.295780) / 1000
            }
        ],
        "special": [],
        "group": [
            {
                "name": "角度制",
                "list": [
                    "圆周",
                    "直角",
                    "百分度",
                    "度",
                    "分",
                    "秒"
                ]
            },
            {
                "name": "弧度制",
                "list": [
                    "弧度",
                    "毫弧度"
                ]
            }
        ]
    },
}

/*
* 计算
* @uType       String,  not null, 单位类型(如length, time)
* @num         Number,  not null, 输入值
* @uFrom       String,  not null, 原单位
* @uTo         String,  not null, 目标单位
* @keepOrigin  Boolean, null，    保持原始结果(不进行格式化)，默认false
*
* return       Object, 计算结果
*/
const calculate = function (type, num, from, to, keepOrigin = false) {
    let fromUnit = getUnit(type, from)
    if (from === to) {
        return {
            num: keepOrigin ? num : format(num),
            unitFirst: fromUnit.zh,
            unitSecond: fromUnit.en
        }
    }
    let toUnit = getUnit(type, to)

    let special = getSpecial(type, from, to)
    if (special !== null) {
        num = special(num)
    } else {
        num = toUnit.calc(fromUnit.init(num))
    }
    return {
        num: keepOrigin ? num : format(num),
        unitFirst: toUnit.zh,
        unitSecond: toUnit.en
    }
}


const getCategory = (type) => {
    return CONFIG[type]
}

const getUnit = (type, name) => {
    let category = getCategory(type)
    for (let i = 0; i < category.unit.length; i++) {
        if (name === category.unit[i].name) {
            return category.unit[i];
        }
    }
}

const getSpecial = (type, from, to) => {
    let category = getCategory(type)
    if (category.special.length > 0) {
        for (let i = 0; i < category.special.length; i++) {
            if (from === category.special[i].from && to === category.special[i].to) {
                return category.special[i].func;
            }
        }
    }
    return null;
}

/*
 * 对结果进行格式化(内部使用)
 */
const format = function (num) {
    //格式策略，整体不超过14位
    let strNum = num + '',
        isFloat = false,
        arr, intPart, decPart
    //只有包括.且整数位小于14位才认为是浮点数（便于以后格式化）
    if (strNum.indexOf('.') > -1) {
        let match = strNum.match(/\.\d+e[+-](\d+)$/)
        if (match && match[1]) {
            isFloat = match[1] * 1 < (MAX_NUM - 1) ? true : false
        } else {
            isFloat = true
        }
    }
    //小数处理逻辑
    if (isFloat) {
        //-1 ~ 1之间的小数
        if (num > -1 && num < 1 && num != 0) {
            //小数位开始有5个及以上0，转换为科学计数法，计数小数保留四位
            if (Math.abs(num) < 0.00001) {
                num = exponential(num, EXPONENTIAL_NUM)
            } else {
                //保留7位小数
                num = num.toFixed(DECIMAL_NUM) * 1
            }
        } else {
            arr = strNum.split('.')
            intPart = arr[0]
            decPart = arr[1]
            //整体超长
            if (strNum.length > MAX_NUM) {
                //整数部分超长
                if (intPart.length >= MAX_NUM) {
                    num = exponential(num, EXPONENTIAL_NUM)
                } else {
                    if (intPart.length < DECIMAL_NUM - 1) {
                        num = num.toFixed(DECIMAL_NUM) * 1
                    } else {
                        num = num.toFixed(MAX_NUM - intPart.length - 1) * 1
                    }
                }
            } else {
                if (decPart.length > DECIMAL_NUM) {
                    num = num.toFixed(DECIMAL_NUM) * 1
                }
            }
        }
    } else {
        if (strNum.length > MAX_NUM) {
            num = exponential(num, EXPONENTIAL_NUM)
        }
    }
    return num + ''
}

/*
 * 科学计数法快捷函数(内部使用)
 */
const exponential = function (num, n) {
    //保留科学计数法小数后n位
    let numExp = num.toExponential(n)
    //如果计数小数位均为0，去掉
    return (numExp + '').match(new RegExp('.0{' + n + '}e')) ? num.toExponential(0) : numExp
}

export default {
    //返回某一类的所有配置项
    getData: function (type) {
        return _.cloneDeep(getCategory(type).group).map((item) => {
            item.list = item.list.map((name) => {
                let unit = getUnit(type, name)
                return {
                    name,
                    unit: unit.zh + (unit.en ? ` (${unit.en})` : '')
                }
            })
            return item;
        })
    },
    getMain(type) {
        return getCategory(type).main
    },
    //计算，返回格式化后的结果
    calc: function (type, x, from, to) {
        return calculate(type, x, from, to)
    },
    //计算，返回原始结果
    calcOrigin: function (type, x, from, to) {
        return calculate(type, x, from, to, true)
    },
    //格式化
    format: function (num) {
        return format(num)
    },
    list: () => {
        return Object.keys(CONFIG).map((key) => {
            return {key, name: CONFIG[key].name}
        })
    }
}
